﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using ParaEditor.DAO;
using ParaEditor.Domain.Entities;
using ParaEditor.DomainSource.Entities;

namespace ParaEditor.Desktop.Helper
{
    public class DomainConvert
    {
        public static List<QfPercent> ConvertToQfPercent(List<QfPercentAll> objList)
        {
            List<QfPercent> list = new List<QfPercent>();
            QfPercent obj;
            QfPercentPk objPk;
            foreach (QfPercentAll item in objList)
            {
                obj = new QfPercent();
                objPk = new QfPercentPk();
                objPk.infoVer = item.qfPercentAllPk.infoVer;
                objPk.recordId = item.qfPercentAllPk.recordId;
                obj.qfPercentPk = objPk;
                obj.inOutStationId = item.inOutStationId;
                obj.outInStationId = item.outInStationId;
                obj.benfNumber = item.benfNumber;
                obj.benfId1 = item.benfId1;
                obj.percentRate1 = item.percentRate1;
                obj.benfId2 = item.benfId2;
                obj.percentRate2 = item.percentRate2;
                obj.benfId3 = item.benfId3;
                obj.percentRate3 = item.percentRate3;
                obj.benfId4 = item.benfId4;
                obj.percentRate4 = item.percentRate4;
                obj.benfId5 = item.benfId5;
                obj.percentRate5 = item.percentRate5;
                obj.benfId6 = item.benfId6;
                obj.percentRate6 = item.percentRate6;
                obj.benfId7 = item.benfId7;
                obj.percentRate7 = item.percentRate7;
                obj.benfId8 = item.benfId8;
                obj.percentRate8 = item.percentRate8;
                obj.benfId9 = item.benfId9;
                obj.percentRate9 = item.percentRate9;
                obj.benfId10 = item.benfId10;
                obj.percentRate10 = item.percentRate10;
                obj.benfId11 = item.benfId11;
                obj.percentRate11 = item.percentRate11;
                obj.benfId12 = item.benfId12;
                obj.percentRate12 = item.percentRate12;
                obj.benfId13 = item.benfId13;
                obj.percentRate13 = item.percentRate13;
                obj.benfId14 = item.benfId14;
                obj.percentRate14 = item.percentRate14;
                obj.benfId15 = item.benfId15;
                obj.percentRate15 = item.percentRate15;
                obj.benfId16 = item.benfId16;
                obj.percentRate16 = item.percentRate16;
                obj.benfId17 = item.benfId17;
                obj.percentRate17 = item.percentRate17;
                obj.tranNumber = item.tranNumber;
                obj.tran1 = item.tran1;
                obj.tran2 = item.tran2;
                obj.tran3 = item.tran3;
                obj.tran4 = item.tran4;
                obj.tran5 = item.tran5;
                obj.tran6 = item.tran6;
                obj.tran7 = item.tran7;
                obj.tran8 = item.tran8;
                obj.tran9 = item.tran9;
                obj.infoTime = item.infoTime;
                obj.benfId18 = item.benfId18;
                obj.percentRate18 = item.percentRate18;
                obj.benfId19 = item.benfId19;
                obj.percentRate19 = item.percentRate19;
                obj.benfId20 = item.benfId20;
                obj.percentRate20 = item.percentRate20;
                obj.benfId21 = item.benfId21;
                obj.percentRate21 = item.percentRate21;
                obj.benfId22 = item.benfId22;
                obj.percentRate22 = item.percentRate22;
                obj.benfId23 = item.benfId23;
                obj.percentRate23 = item.percentRate23;
                obj.benfId24 = item.benfId24;
                obj.percentRate24 = item.percentRate24;
                obj.benfId25 = item.benfId25;
                obj.percentRate25 = item.percentRate25;
                obj.tran10 = item.tran10;
                obj.tran11 = item.tran11;
                obj.tran12 = item.tran12;
                obj.tran13 = item.tran13;
                obj.tran14 = item.tran14;
                obj.tran15 = item.tran15;
                obj.tran16 = item.tran16;
                obj.tran17 = item.tran17;
                obj.tran18 = item.tran18;
                obj.tran19 = item.tran19;
                obj.tran20 = item.tran20;
                obj.tran21 = item.tran21;
                obj.tran22 = item.tran22;
                obj.tran23 = item.tran23;
                obj.tran24 = item.tran24;
                obj.tran25 = item.tran25;
                obj.tran26 = item.tran26;
                obj.tran27 = item.tran27;
                obj.tran28 = item.tran28;
                obj.tran29 = item.tran29;
                obj.tran30 = item.tran30;
                obj.benfId26 = item.benfId26;
                obj.percentRate26 = item.percentRate26;
                obj.benfId27 = item.benfId27;
                obj.percentRate27 = item.percentRate27;
                obj.benfId28 = item.benfId28;
                obj.percentRate28 = item.percentRate28;
                obj.benfId29 = item.benfId29;
                obj.percentRate29 = item.percentRate29;
                obj.benfId30 = item.benfId30;
                obj.percentRate30 = item.percentRate30;
                obj.benfId31 = item.benfId31;
                obj.percentRate31 = item.percentRate31;
                obj.benfId32 = item.benfId32;
                obj.percentRate32 = item.percentRate32;
                obj.benfId33 = item.benfId33;
                obj.percentRate33 = item.percentRate33;
                obj.benfId34 = item.benfId34;
                obj.percentRate34 = item.percentRate34;
                obj.benfId35 = item.benfId35;
                obj.percentRate35 = item.percentRate35;
                obj.infoTimeOut = item.infoTimeOut;
                obj.price = item.price;
                list.Add(obj);
            }
            return list;
        }

        /// <summary>
        /// 受益方转换
        /// </summary>
        /// <param name="objList">secu下的受益方信息集</param>
        /// <param name="infoVer">在proc下的版本号</param>
        /// <returns></returns>
        public static IList<BenfInfo> ConvertToBenfInfo(IList<OwnerInfo> objList,int infoVer)
        { 
            IList<BenfInfo> listDesc = new List<BenfInfo>();
            BenfInfo objDesc = null;
            BenfInfoPk objPk = null;
            foreach (OwnerInfo item in objList)
            {
                objPk = new BenfInfoPk();
                objDesc = new BenfInfo();
                objPk.benfVer = infoVer;
                objPk.benfId = item.ownerInfoPk.ownerId.ToString().PadLeft(4, '0'); 
                objDesc.benfInfoPk = objPk;
                objDesc.benfName = item.ownerDesc;
                //lineID因TBL_CR_OWNER_INFO缺少字段 暂时用ownerid代替
                objDesc.lineId = item.ownerInfoPk.ownerId.ToString().PadLeft(2, '0');
                listDesc.Add(objDesc);
            }
            return listDesc;
        }

        public static IList<Para3006> ConvertToPara3006(IList<CrStationInfo> objList, int infoVer)
        {
            IList<Para3006> listDesc = new List<Para3006>();
            Para3006 objDesc = null;
            Para3006Pk objPk = null;
            foreach (CrStationInfo item in objList)
            {
                objPk = new Para3006Pk();
                objPk.StationVer = infoVer;
                objPk.StationNid = item.crStationInfoPk.lineId.ToString().PadLeft(2, '0') + item.crStationInfoPk.stationId.ToString().PadLeft(2, '0') + "1000";
                objDesc = new Para3006();
                objDesc.para3006Pk = objPk;
                objDesc.LineId = item.crStationInfoPk.lineId.ToString().PadLeft(2, '0');
                objDesc.LineIdbcd = item.crStationInfoPk.lineId.ToString().PadLeft(2, '0');
                objDesc.OwnerId = objDesc.LineId;
                objDesc.StaId = item.crStationInfoPk.stationId;
                objDesc.StationIdbcd = item.crStationInfoPk.stationId.ToString().PadLeft(2, '0');
                objDesc.StationNmCn = item.stationName.Trim();
                objDesc.StationNmEn = item.stationNameEn;
                listDesc.Add(objDesc);
            }
            return listDesc;
        }

        public static IList<Para3007> ConvertToPara3007(IList<CrLineInfo> objList, int infoVer)
        {
            IList<Para3007> listDesc = new List<Para3007>();
            Para3007 objDesc = null;
            Para3007Pk objPk = null;
            foreach (CrLineInfo item in objList)
            {
                objPk = new Para3007Pk();
                objPk.InfoVer = infoVer;
                objPk.LineID = item.crLineInfoPk.lineId.ToString().PadLeft(2, '0');
                objDesc = new Para3007();
                objDesc.para3007Pk = objPk;
                objDesc.LineIdbcd = objPk.LineID + "00";
                objDesc.LineNmCn = item.lineName.Trim();
                objDesc.LineNmEn = item.lineNameEn;
                listDesc.Add(objDesc);
            }
            return listDesc;
        }

        /// <summary>
        /// 换乘站转换
        /// </summary>
        /// <param name="objList">清分比例</param>
        /// <param name="tranList">换乘站列表信息</param>
        /// <param name="hTablePrice">进出站对应的票价信息</param>
        /// <param name="infoVer">版本号</param>
        /// <returns></returns>
        public static List<QfPercentAll> ConvertToParaQfPercentAll(IList<IncomeProportion> objList,List<TranStation> tranList,Hashtable hTablePrice,int infoVer)
        {
            string datetime = DateTime.Now.ToString("yyyyMMdd").PadRight(14,'0');
            Hashtable benfInfoHTable = GetBenfInfoIntoHashtable(objList);
            Hashtable tranHTable = GetTranStationInfoHashtable(tranList);

            List<QfPercentAll> listDesc = new List<QfPercentAll>();
            QfPercentAll objDesc = null;
            QfPercentAllPk objPk = null;
            string tmpID = "";
            StringBuilder sb = new StringBuilder();
            int recordId = 0;
            foreach (IncomeProportion item in objList)
            {
                objDesc = new QfPercentAll();
                objDesc.inOutStationId = item.incomeProportionPk.OId.ToString().PadLeft(4, '0');
                objDesc.outInStationId = item.incomeProportionPk.DId.ToString().PadLeft(4, '0');
                sb.Append(objDesc.inOutStationId);
                sb.Append(objDesc.outInStationId);

                if (!tmpID.Equals(sb.ToString()))
                {
                    objPk = new QfPercentAllPk();
                    objPk.infoVer = infoVer;
                    objPk.recordId = recordId++;
                    objDesc.qfPercentAllPk = objPk;
                    objDesc.infoTimeOut = "20991231235959";
                    objDesc.infoTime = datetime;
                    listDesc.Add(objDesc);
                }
                tmpID = sb.ToString();
                sb.Clear();
            }
            
            //收益方行转列
            ConvertBenfFromRowToColumn(ref listDesc, benfInfoHTable);
            //换乘站行转列
            ConvertTranStationFromRowToColumn(ref listDesc, tranHTable);
            //取除重复数据
            //List<QfPercentAll> distinctList = Distinct(listDesc);
            //对收益方数量 换乘站数量 票价字段赋值
            InitPrice(ref listDesc, hTablePrice);
            return listDesc;
        }

        /// <summary>
        /// 子路段信息转换
        /// </summary>
        /// <param name="objList"></param>
        /// <param name="infoVer"></param>
        /// <returns></returns>
        public static IList<Para4030> ConvertToPara4030(IList<SubRoad> objList, int infoVer)
        {
            SourceBaseDAO dao = new SourceBaseDAO();
            StringBuilder sBuilder = new StringBuilder();
            Hashtable tableCount = new Hashtable();//走法
            Hashtable tableSubCount = new Hashtable();//子路段数量
            tableCount = dao.InitWayCountHashTable();
            tableSubCount = dao.InitSubRoadCountHashTable();
            IList<Para4030> listDesc = new List<Para4030>();
            Para4030 param = null;
            Para4030Pk paramPk = null;
            foreach (SubRoad item in objList)
            {
                paramPk = new Para4030Pk();
                param = new Para4030();
                paramPk.infoVer = infoVer;
                //od编号
                paramPk.odSeq = item.subRoadPk.roadSeq;
                paramPk.ioStat = item.subRoadPk.OId.ToString().PadLeft(4,'0');
                paramPk.oiStat = item.subRoadPk.DId.ToString().PadLeft(4, '0');
                //组key
                sBuilder.Append(paramPk.odSeq);
                sBuilder.Append(paramPk.ioStat);
                sBuilder.Append(paramPk.oiStat);
                //走法数量
                paramPk.odWayCount = (int)tableCount[sBuilder.ToString()];
                
                //走法顺序号
                paramPk.odId = item.subRoadPk.wayId;
                //组key
                sBuilder.Append(item.subRoadPk.wayId);
                //子路段数量
                paramPk.subCount = (long)tableSubCount[sBuilder.ToString()];
                sBuilder.Clear();
                //子路段顺序号
                paramPk.subId = item.subRoadPk.subroadSeq;
                paramPk.wayPercent = item.subRoadPk.wayPercent * 100;
                paramPk.subIoStat = item.subRoadPk.subOrigIndex.ToString().PadLeft(4,'0');
                paramPk.subOiStat = item.subRoadPk.subDestIndex.ToString().PadLeft(4, '0');
                paramPk.subroadLength = item.subRoadPk.subroadLength;
                paramPk.subTime = Int16.Parse(item.subRoadPk.subroadTime.ToString());
                param.para4030Pk = paramPk;
                listDesc.Add(param);
            }
            return listDesc;
        }

        /// <summary>
        /// 4004 区域表转换
        /// </summary>
        /// <param name="objList"></param>
        /// <param name="infoVer"></param>
        /// <returns></returns>
        public static IList<Para4004> ConvertToPara4004(IList<CalcArea> objList, int infoVer)
        {
            IList<Para4004> resultList = new List<Para4004>();
            Para4004 param = null;
            Para4004Pk paramPk = null;
            int areaID = 0;
            foreach (CalcArea item in objList)
            {
                if (item != null)
                {
                    areaID++;
                    paramPk = new Para4004Pk();
                    param = new Para4004();
                    paramPk.infoVer = infoVer;
                    paramPk.areaId = areaID;
                    param.para4004Pk = paramPk;
                    param.ownerStation = item.calcAreaPk.OId.ToString().PadLeft(4, '0');
                    param.inStationId = item.calcAreaPk.DId.ToString().PadLeft(4, '0');
                    param.lineId = item.calcAreaPk.OId.ToString().PadLeft(4, '0').Substring(0, 2);
                    param.areaInfo = Int16.Parse(item.areaCode.ToString());
                    param.areaResv = 0;
                    resultList.Add(param);
                }
            }
            return resultList;
        }


        /// <summary>
        /// 根据key将换乘站查询进列表 将存储换乘站的列表存储为哈希表的value
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private static Hashtable GetTranStationInfoHashtable(List<TranStation> list)
        {
            List<string> listTmp = new List<string>();
            Hashtable resultList = new Hashtable();
            string tmpClusters = "";
            string tmpstr;
            foreach (TranStation item in list)
            {
                tmpstr = item.key;
                if (tmpClusters.Equals(tmpstr))
                {
                    listTmp.Add(item.value);
                    resultList.Remove(tmpstr);
                    resultList.Add(tmpstr, listTmp);
                }
                else
                {
                    listTmp = new List<string>();
                    listTmp.Add(item.value);
                    resultList.Add(tmpstr, listTmp);
                }
                tmpClusters = tmpstr;
            }
            return resultList;
        }

        /// <summary>
        /// 根据key将受益方查询进列表 将存储受益方的列表存储为哈希表的value
        /// </summary>
        /// <param name="objList"></param>
        /// <returns></returns>
        private static Hashtable GetBenfInfoIntoHashtable(IList<IncomeProportion> objList)
        {
            Hashtable resultList = new Hashtable();
            List<KeyValue> listTmp = new List<KeyValue>(); 
            StringBuilder tmpKey = new StringBuilder();
            KeyValue tmpKeyValue;
            string tmpClusters = "";
            string tmpstr;
            foreach (IncomeProportion item in objList)
            {
                
                tmpKeyValue = new KeyValue();
                tmpKey.Append(item.incomeProportionPk.OId.ToString().PadLeft(4,'0'));
                tmpKey.Append(item.incomeProportionPk.DId.ToString().PadLeft(4, '0'));
                tmpstr = tmpKey.ToString();
                if (tmpClusters.Equals(tmpstr))
                {
                    tmpKeyValue.benfid = item.incomeProportionPk.ownerId;
                    tmpKeyValue.percentRate = item.incomeProportionPk.incomeProportion;
                    listTmp.Add(tmpKeyValue);
                    resultList.Remove(tmpstr);
                    resultList.Add(tmpstr, listTmp);
                }
                else
                {
                    listTmp = new List<KeyValue>();
                    tmpKeyValue.benfid = item.incomeProportionPk.ownerId;
                    tmpKeyValue.percentRate = item.incomeProportionPk.incomeProportion;
                    listTmp.Add(tmpKeyValue);
                    resultList.Add(tmpstr, listTmp);
                }
                tmpClusters = tmpstr;
                tmpKey.Clear();
            }
            return resultList;
        }


        /// <summary>
        /// 根据进出站ID为票价赋值
        /// </summary>
        /// <param name="objList"></param>
        /// <param name="hashtable"></param>
        private static void InitPrice(ref List<QfPercentAll> objList, Hashtable hashtable)
        {
            StringBuilder keyBuilder = new StringBuilder();
            foreach (QfPercentAll obj in objList)
            {
                keyBuilder.Append(obj.inOutStationId);
                keyBuilder.Append(obj.outInStationId);
                if (hashtable[keyBuilder.ToString()] != null)
                {
                    obj.price = (short)hashtable[keyBuilder.ToString()];
                }
                keyBuilder.Clear();
            }
        }

        /// <summary>
        /// 收益方行转列
        /// </summary>
        /// <param name="objList"></param>
        /// <param name="hashtable"></param>
        private static void ConvertBenfFromRowToColumn(ref List<QfPercentAll> objList, Hashtable hashtable)
        {
            InitBenfInfo(ref objList);
            StringBuilder keyBuilder = new StringBuilder();
            KeyValue defaultObj = null;
            foreach (QfPercentAll obj in objList)
            {
                keyBuilder.Append(obj.inOutStationId);
                keyBuilder.Append(obj.outInStationId);
                List<KeyValue> list = new List<KeyValue>();
                if (hashtable[keyBuilder.ToString()] != null)
                {
                    list = hashtable[keyBuilder.ToString()] as List<KeyValue>;
                }
                else
                {
                    defaultObj = new KeyValue();
                    defaultObj.benfid = 0;
                    defaultObj.percentRate = 0;
                    list.Add(defaultObj);
                }
                keyBuilder.Clear();
                int sumBenf = list.Count;
                obj.benfNumber = sumBenf;//收益方数量
                int offset = 0;
                foreach (KeyValue item in list)
                {
                    if (offset < sumBenf)
                    {
                        string benfid = item.benfid.ToString().PadLeft(4, '0');
                        int percentRate = item.percentRate;
                        switch (offset)
                        {
                            case 0:
                                obj.benfId1 = benfid;
                                obj.percentRate1 = percentRate;
                                break;
                            case 1:
                                obj.benfId2 = benfid;
                                obj.percentRate2 = percentRate;
                                break;
                            case 2:
                                obj.benfId3 = benfid;
                                obj.percentRate3 = percentRate;
                                break;
                            case 3:
                                obj.benfId4 = benfid;
                                obj.percentRate4 = percentRate;
                                break;
                            case 4:
                                obj.benfId5 = benfid;
                                obj.percentRate5 = percentRate;
                                break;
                            case 5:
                                obj.benfId6 = benfid;
                                obj.percentRate6 = percentRate;
                                break;
                            case 6:
                                obj.benfId7 = benfid;
                                obj.percentRate7 = percentRate;
                                break;
                            case 7:
                                obj.benfId8 = benfid;
                                obj.percentRate8 = percentRate;
                                break;
                            case 8:
                                obj.benfId9 = benfid;
                                obj.percentRate9 = percentRate;
                                break;
                            case 9:
                                obj.benfId10 = benfid;
                                obj.percentRate10 = percentRate;
                                break;
                            case 10:
                                obj.benfId11 = benfid;
                                obj.percentRate11 = percentRate;
                                break;
                            case 11:
                                obj.benfId12 = benfid;
                                obj.percentRate12 = percentRate;
                                break;
                            case 12:
                                obj.benfId13 = benfid;
                                obj.percentRate13 = percentRate;
                                break;
                            case 13:
                                obj.benfId14 = benfid;
                                obj.percentRate14 = percentRate;
                                break;
                            case 14:
                                obj.benfId15 = benfid;
                                obj.percentRate15 = percentRate;
                                break;
                            case 15:
                                obj.benfId16 = benfid;
                                obj.percentRate16 = percentRate;
                                break;
                            case 16:
                                obj.benfId17 = benfid;
                                obj.percentRate17 = percentRate;
                                break;
                            case 17:
                                obj.benfId18 = benfid;
                                obj.percentRate18 = percentRate;
                                break;
                            case 18:
                                obj.benfId19 = benfid;
                                obj.percentRate19 = percentRate;
                                break;
                            case 19:
                                obj.benfId20 = benfid;
                                obj.percentRate20 = percentRate;
                                break;
                            case 20:
                                obj.benfId21 = benfid;
                                obj.percentRate21 = percentRate;
                                break;
                            case 21:
                                obj.benfId22 = benfid;
                                obj.percentRate22 = percentRate;
                                break;
                            case 22:
                                obj.benfId23 = benfid;
                                obj.percentRate23 = percentRate;
                                break;
                            case 23:
                                obj.benfId24 = benfid;
                                obj.percentRate24 = percentRate;
                                break;
                            case 24:
                                obj.benfId25 = benfid;
                                obj.percentRate25 = percentRate;
                                break;
                            case 25:
                                obj.benfId26 = benfid;
                                obj.percentRate26 = percentRate;
                                break;
                            case 26:
                                obj.benfId27 = benfid;
                                obj.percentRate27 = percentRate;
                                break;
                            case 27:
                                obj.benfId28 = benfid;
                                obj.percentRate28 = percentRate;
                                break;
                            case 28:
                                obj.benfId29 = benfid;
                                obj.percentRate29 = percentRate;
                                break;
                            case 29:
                                obj.benfId30 = benfid;
                                obj.percentRate30 = percentRate;
                                break;
                            case 30:
                                obj.benfId31 = benfid;
                                obj.percentRate31 = percentRate;
                                break;
                            case 31:
                                obj.benfId32 = benfid;
                                obj.percentRate32 = percentRate;
                                break;
                            case 32:
                                obj.benfId33 = benfid;
                                obj.percentRate33 = percentRate;
                                break;
                            case 33:
                                obj.benfId34 = benfid;
                                obj.percentRate34 = percentRate;
                                break;
                            case 34:
                                obj.benfId35 = benfid;
                                obj.percentRate35 = percentRate;
                                break;
                            default:
                                break;
                        }
                    }
                    offset++;
                }
            }
        }

        /// <summary>
        /// 换乘站行转列
        /// </summary>
        /// <param name="objList"></param>
        /// <param name="hashtable"></param>
        private static void ConvertTranStationFromRowToColumn(ref List<QfPercentAll> objList, Hashtable hashtable)
        {
            InitTranStation(ref objList);
            StringBuilder keyBuilder = new StringBuilder();
            foreach (QfPercentAll obj in objList)
            {
                keyBuilder.Append(obj.inOutStationId);
                keyBuilder.Append(obj.outInStationId);
                List<string> list = new List<string>();
                if (hashtable[keyBuilder.ToString()] != null)
                {
                    list = hashtable[keyBuilder.ToString()] as List<string>;
                    int sumTran = list.Count;
                    obj.tranNumber = sumTran;
                    int offset = 0;
                    foreach (string item in list)
                    {
                        if (offset < sumTran)
                        {
                            switch (offset)
                            {
                                case 0:
                                    obj.tran1 = item;
                                    break;
                                case 1:
                                    obj.tran2 = item;
                                    break;
                                case 2:
                                    obj.tran3 = item;
                                    break;
                                case 3:
                                    obj.tran4 = item;
                                    break;
                                case 4:
                                    obj.tran5 = item;
                                    break;
                                case 5:
                                    obj.tran6 = item;
                                    break;
                                case 6:
                                    obj.tran7 = item;
                                    break;
                                case 7:
                                    obj.tran8 = item;
                                    break;
                                case 8:
                                    obj.tran9 = item;
                                    break;
                                case 9:
                                    obj.tran10 = item;
                                    break;
                                case 10:
                                    obj.tran11 = item;
                                    break;
                                case 11:
                                    obj.tran12 = item;
                                    break;
                                case 12:
                                    obj.tran13 = item;
                                    break;
                                case 13:
                                    obj.tran14 = item;
                                    break;
                                case 14:
                                    obj.tran15 = item;
                                    break;
                                case 15:
                                    obj.tran16 = item;
                                    break;
                                case 16:
                                    obj.tran17 = item;
                                    break;
                                case 17:
                                    obj.tran18 = item;
                                    break;
                                case 18:
                                    obj.tran19 = item;
                                    break;
                                case 19:
                                    obj.tran20 = item;
                                    break;
                                case 20:
                                    obj.tran21 = item;
                                    break;
                                case 21:
                                    obj.tran22 = item;
                                    break;
                                case 22:
                                    obj.tran23 = item;
                                    break;
                                case 23:
                                    obj.tran24 = item;
                                    break;
                                case 24:
                                    obj.tran25 = item;
                                    break;
                                case 25:
                                    obj.tran26 = item;
                                    break;
                                case 26:
                                    obj.tran27 = item;
                                    break;
                                case 27:
                                    obj.tran28 = item;
                                    break;
                                case 28:
                                    obj.tran29 = item;
                                    break;
                                case 29:
                                    obj.tran30 = item;
                                    break;
                                default:
                                    break;
                            }
                        }
                        offset++;
                    }
                }
                keyBuilder.Clear();
            }
        }

        private static void InitTranStation(ref List<QfPercentAll> objList)
        {
            foreach (QfPercentAll item in objList)
            {
                item.tran1 = "0000";
                item.tran2 = "0000";
                item.tran3 = "0000";
                item.tran4 = "0000";
                item.tran5 = "0000";
                item.tran6 = "0000";
                item.tran7 = "0000";
                item.tran8 = "0000";
                item.tran9 = "0000";
                item.tran10 = "0000";
                item.tran11 = "0000";
                item.tran12 = "0000";
                item.tran13 = "0000";
                item.tran14 = "0000";
                item.tran15 = "0000";
                item.tran16 = "0000";
                item.tran17 = "0000";
                item.tran18 = "0000";
                item.tran19 = "0000";
                item.tran20 = "0000";
                item.tran21 = "0000";
                item.tran22 = "0000";
                item.tran23 = "0000";
                item.tran24 = "0000";
                item.tran25 = "0000";
                item.tran26 = "0000";
                item.tran27 = "0000";
                item.tran28 = "0000";
                item.tran29 = "0000";
                item.tran30 = "0000";
            }
        }

        private static void InitBenfInfo(ref List<QfPercentAll> objList)
        {
            foreach (QfPercentAll item in objList)
            {
                item.benfId1 = "0000";
                item.benfId2 = "0000";
                item.benfId3 = "0000";
                item.benfId4 = "0000";
                item.benfId5 = "0000";
                item.benfId6 = "0000";
                item.benfId7 = "0000";
                item.benfId8 = "0000";
                item.benfId9 = "0000";
                item.benfId10 = "0000";
                item.benfId11 = "0000";
                item.benfId12 = "0000";
                item.benfId13 = "0000";
                item.benfId14 = "0000";
                item.benfId15 = "0000";
                item.benfId16 = "0000";
                item.benfId17 = "0000";
                item.benfId18 = "0000";
                item.benfId19 = "0000";
                item.benfId20 = "0000";
                item.benfId21 = "0000";
                item.benfId22 = "0000";
                item.benfId23 = "0000";
                item.benfId24 = "0000";
                item.benfId25 = "0000";
                item.benfId26 = "0000";
                item.benfId27 = "0000";
                item.benfId28 = "0000";
                item.benfId29 = "0000";
                item.benfId30 = "0000";
                item.benfId31 = "0000";
                item.benfId32 = "0000";
                item.benfId33 = "0000";
                item.benfId34 = "0000";
                item.benfId35 = "0000";
            }
        }

        /// <summary>
        /// 去除重复数据
        /// </summary>
        /// <param name="listDesc"></param>
        private static List<QfPercentAll> Distinct(List<QfPercentAll> listDesc)
        {
            List<QfPercentAll> distinctList = new List<QfPercentAll>();
            StringBuilder sb = new StringBuilder();
            string tmpID = "";
            foreach (QfPercentAll item in listDesc)
            {
                sb.Append(item.inOutStationId.PadLeft(4, '0'));
                sb.Append(item.outInStationId.PadLeft(4, '0'));
                if (!tmpID.Equals(sb.ToString()))
                {
                    distinctList.Add(item);
                }
                tmpID = sb.ToString();
                sb.Clear();
            }
            return distinctList;
        }

        class KeyValue
        {
            public int benfid { get; set; }
            public int percentRate { get; set; }
        }
    }
}
